home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter2 / 2.31 / 2.31.cs next >
Encoding:
Text File  |  2004-08-31  |  417 b   |  18 lines

  1. /* Boxing and unboxing. */
  2. using System;
  3.  
  4. namespace Chapter2 {
  5.     class Class1 {
  6.         static void Main() {
  7.             double Happy = 4.0;
  8.  
  9.             object MrBox = Happy;
  10.  
  11.             // This line should work well
  12.             double StillHappy = (double)MrBox;
  13.  
  14.             // This line may compile, but it will surely fail on execution
  15.             int NotHappy = (int)MrBox;
  16.         }
  17.     }
  18. }